<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet"
	href="http://static.runoob.com/assets/js/jquery-treeview/jquery.treeview.css" />
<!-- <link rel="stylesheet" href="css/screen.css" /> -->

<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<!-- <script src="js/jquery.cookie.js"></script> -->
<script
	src="http://static.runoob.com/assets/js/jquery-treeview/jquery.treeview.js"
	type="text/javascript"></script>
<meta hzttp-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>学生答案</title>
</head>
<style>
textarea {
	width: 99%;
	height: 100%;
}
</style>
<script
	src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
	$(document).ready(
			function() {

				var jsonObj;
				var userId = getUrlParam('id');
				var examdate = getUrlParam('date');
				var operations = getUrlParam('operation');

				$.ajax({
					type : "GET",
					url : "Answer/getname/" + userId,
					// 					dataType : "json",
					contentType : "application/json",
					success : function(data) {
						$("#banner").append(data)
					},
					error : function(data) {
						alert("请求错误");
					}
				});

				$.ajax({
					type : "GET",
					url : "Answer/search/" + userId + "/" + examdate + "/"
							+ operations,
					// 					dataType : "json",
					contentType : "application/json",
					success : function(data) {
						jsonObj = JSON.parse(data)
						var branches;
						$.each(jsonObj, function(key, value) {
							branches = "<li><span class='file'>" + key
									+ "</span></li>";
							$("#browser").append(branches);
						})
					},
					error : function(data) {
						alert("请求错误");
					}
				});

				$("#browser").on('click', '.file', function() {
					var tmp = $(this).text();
					$.each(jsonObj, function(key, value) {
						if (tmp == key) {
							$("#div1").empty();
							$("#div1").append(value);
						}
					});

				});
				$("#submit").click(function() {
					// 					alert(userId)
					// 					alert(examdate)
					// 					alert($('input:radio:checked').val())
					// 					alert($("#tarea3").val())
					$.ajax({
						type : "POST",
						url : "Answer/submit",
						// 						dataType : "json",
						contentType : "application/json",
						data : JSON.stringify({
							userId : userId,
							date : examdate,
							operation : operations,
							score : $('input:radio:checked').val(),
							comment : $("#tarea3").val()
						}),
						success : function(data) {
							window.opener.location.reload(); //刷新父窗口中的网页

							window.close();//关闭当前窗窗口
							// 							window.close();
						},
						error : function(data) {
							// 							window.opener.location.reload(); //刷新父窗口中的网页

							window.close();//关闭当前窗窗口
							// 							alert("提交错误");
						}
					});
				});
				function getUrlParam(name) {
					var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
					var r = window.location.search.substr(1).match(reg); //匹配目标参数
					if (r != null)
						return unescape(r[2]);
					return null; //返回参数值
				}
			});
</script>

<body>

	<h3 id="banner">作业查看</h3>
	<hr>
	<div id="main" style="width: 100%">
		<div style="width: 15%; float: left;">
			<ul id="browser" class="filetree treeview-famfamfam">
			</ul>
		</div>
		<div id="div1"
			style="width: 84%; height: 600px; float: left; overflow-y: scroll"></div>
		<div style="clear: both;"></div>
	</div>
	<div style="width: 33%; float: left">
		评语
		<textarea name="comment" id="tarea3" rows="10" cols="35"
			style="background: transparent"></textarea>

	</div>
	<div id="div1" style="width: 33%; float: left">
		打分<br /> <input value="A" type="radio" id="score">A
		&nbsp;&nbsp;&nbsp; <input value="B" type="radio" id="score">B
		<br /> <input value="C" type="radio" id="score">C
		&nbsp;&nbsp;&nbsp; <input value="D" type="radio" id="score">D
	</div>
	<div style="width: 33%; float: left">
		<button id="submit">确认</button>
	</div>
</body>
</html>